package com.foxire.demo;

import java.util.Scanner;

public class MovieOperator {
    // 电影操作类

    private Movie[] movies;// 电影数组

    public MovieOperator(Movie[] movies) {
        this.movies = movies;
    }

    //打印全部电影信息
    public void printMovie() {
        System.out.println("id\t\tname\t\tactor\t\tprice");
        for (int i = 0; i<movies.length; i++){
            Movie movie = movies[i];
            System.out.println(movie.getId()+" "+movie.getName()+" "+movie.getActor()+" "+movie.getPrice());
        }
    }

    // 根据id查询
    public void searchMovie() {
        System.out.println("请输入要查询的电影id");
        Scanner scanner = new Scanner(System.in);
        int id = scanner.nextInt();
        for (int i = 0; i<movies.length; i++){
            if (movies[i].getId() == id){
                System.out.println(movies[i].getId()+" "+movies[i].getName()+" "+movies[i].getActor()+" "+movies[i].getPrice());
                return;
            }
        }
        System.out.println("未找到该电影");
    }
}
